package com.wondertek.poms.dao.po;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.wondertek.poms.common.constant.CurrentUser;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Proxy;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @author gaozhengxing gaozhenghang@wondertek.com.cn
 * @date 2020/12/22 17:57
 * @description TODO
 */
@Data
@Entity
@Table(name = "PRODUCT_PROP")
@DynamicInsert
@DynamicUpdate
@Proxy(lazy = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProductProp implements Serializable {
    private static final long serialVersionUID = 341168294709465100L;

    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "PRODUCT_PROP_SEQ")
    @SequenceGenerator(name = "PRODUCT_PROP_SEQ", allocationSize = 1, sequenceName = "PRODUCT_PROP_SEQ")
    public Long id;

    @Column(name = "PRODUCT_PROP_NAME")
    public String productPropName;

    @Column(name = "PRODUCT_PROP_DESC")
    public String productPropDesc;

    @Column(name = "PROP_VALUE")
    public Long  propValue;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "UPDATE_TIME")
    public Date updateTime;

    public String updater;

    /**
     *   创建时间
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name="CREATE_TIME")
    private Date createTime;


    @Column(name = "CREATOR")
    public String creator;

    public static void putTimeAndUser(ProductProp productProp) {
        productProp.setCreator(CurrentUser.currUserName());
        productProp.setCreateTime(new Date());
    }

    public static void updateTimeAndUser(ProductProp productProp) {
        productProp.setUpdater(CurrentUser.currUserName());
        productProp.setUpdateTime(new Date());
    }

}
